/**
 * jessibuca 播放器
 */
Vue.component('player', {
    props: {},
    data() {
        return {
            jessibucaPlay: null,
        }
    },
    mounted() {
    },
    methods: {
        create(options) {
            options = options || {}
            this.jessibucaPlay = new window.Jessibuca(
                Object.assign({
                        container: this.$refs.container,
                        videoBuffer: 1, // 缓存时长
                        decoder: '/static/jessibuca/decoder.js',
                        hasAudio: false, //不解码声音
                        supportDblclickFullscreen: true, //双击全屏
                        isResize: true,
                        useMSE: false,      //硬解码
                        text: "",
                        loadingText: "加载中",
                        showBandwidth: true, // 显示网速
                        operateBtns: {
                            fullscreen: true,
                            screenshot: true,
                            play: true,
                            audio: true,
                        },
                        forceNoOffscreen: true, //如果多屏出现黑屏，此参数设置为false
                        isNotMute: false,
                        timeout: 10
                    },
                    options
                )
            )
        },

        destory: function () {
            if (this.jessibucaPlay) {
                // 停止播放
                this.jessibucaPlay.destroy();
                this.jessibucaPlay = null;
            }
        },

        play: function (url) {
            this.create()
            let that = this
            that.jessibucaPlay.on("load", function () {
                that.jessibucaPlay.play(url);
            })
        },

    },
    template: `
        <div id="container" ref="container" muted style="min-width: 100px; min-height: 100px; background-color: #000"></div>
    `
});